home *** CD-ROM | disk | FTP | other *** search
- unit Hex;
- interface
- uses SysUtils;
-
- Type
- EHexValError = class(Exception);
-
- EBadHexString = class(EHexValError);
- EHexConversion= class(EHexValError);
-
-
- function HexVal(HexStr: String): LongInt;
-
- implementation
-
- function HexVal(HexStr: String): LongInt;
- var i: Integer;
- begin
- { pre-condition: HexStr contains only ['0'..'9','A'..'F'] }
- for i:=1 to Length(HexStr) do
- begin
- HexStr[i] := UpCase(HexStr[i]);
- if not (HexStr[i] in ['0'..'9','A'..'F']) then
- raise EBadHexString.Create('Bad HexStr "'+HexStr+'" passed.')
- end;
- { convert HexStr to LongInt }
- Val('$'+HexStr,Result,i);
- if i <> 0 then
- raise EHexConversion.Create(
- Format('Error at position: %d of HexStr %s',[i,HexStr]))
- end {HexVal};
-
- end.
-